import kgdlg.IO
import argparse
import kgdlg.utils.misc_utils as utils
import torch
import json
import kgdlg
parser = argparse.ArgumentParser()
parser.add_argument('-train_data', type=str)
parser.add_argument('-save_data', type=str)
parser.add_argument('-config', type=str)
args = parser.parse_args()

opt = utils.load_hparams(args.config)

if opt.random_seed > 0:
    torch.manual_seed(opt.random_seed)

# 首先fileds应该是没有什么问题
fields = kgdlg.IO.get_fields()

# print("当前的fields是什么样子：",fields)

print("Building Training...")


#
train = kgdlg.IO.PriorTrainDataset_forbuild_vocab(
    data_path=args.train_data,
    fields = [(f,fields[f]) for f in fields])
print("Building Vocsab...")
kgdlg.IO.build_vocab(train, opt)

print("Saving fields")
torch.save(kgdlg.IO.save_fields_to_vocab(fields),open(args.save_data+'.vocab.pt', 'wb'))
print("build过程结束，等待输出")
print("观察vocab：",vars(fields['tgt'])['vocab'])
print("build_vocab的结束")
